//==========================================================================//
//                                                                          //
//  DHT22 Library               Version 0.1                     March 2012  //
//                                                                          //
//  Written for the Arduino Duemilanove w/ ATmega328                        //
//                                                                          //
//  DHT22 Arduino Library                                              //
//                                                                          //
//  Created by JFLagarde (jeanfrancoislagarde@hotmail.com)                  //
//                                                                          //
//  This file is part of OpenWS (http://code.google.com/p/openws/)          //
//                                                                          //
//==========================================================================//
//                                                                          //
//  Notes:                                                                  //
//                                                                          //
//                                                                          //
//==========================================================================//
//                                                                          //
//  Copyright 2012 Jean-Francois Lagarde (jeanfrancoislagarde@hotmail.com)  //
//  This program is distributed under the terms of                          //
//  the GNU General Public License                                          //
//                                                                          //
//  This program is free software: you can redistribute it and/or modify    //
//  it under the terms of the GNU General Public License as published by    //
//  the Free Software Foundation, either version 3 of the License, or       //
//  (at your option) any later version.                                     //
//                                                                          //
//  This program is distributed in the hope that it will be useful,         //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of          //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           //
//  GNU General Public License for more details.                            //
//                                                                          //
//  You should have received a copy of the GNU General Public License       //
//  along with this program.  If not, see <http://www.gnu.org/licenses/>.   //
//                                                                          //
//==========================================================================//

#include <DHT22.h>

DHT22 myDHT22 = DHT22();

void setup()
{
	Serial.begin(9600);
	Serial.println("DHT TEST PROGRAM ");
	Serial.println();
	Serial.println("Type,\tstatus,\tTemperature (C),\tHumidity (%)");
	myDHT22.init(5);
}

void loop() {
	// READ DATA
	Serial.print("DHT22, \t");
	int chk = myDHT22.read();
	
	switch (chk) {
		case 0:  Serial.print("OK,\t"); break;
		case -1: Serial.print("Checksum error,\t"); break;
		case -2: Serial.print("Time out error,\t"); break;
		default: Serial.print("Unknown error,\t"); break;
	}
	// DISPLAT DATA
	Serial.print(myDHT22.getTemperature()/10);
	Serial.print(".");
	Serial.print(myDHT22.getTemperature()%10);
	Serial.print(", ");
	Serial.print(myDHT22.getHumidity()/10);
	Serial.print(".");
	Serial.println(myDHT22.getHumidity()%10);

	delay(1000);
}